package com.example.picturestorage.retry;

import com.example.picturestorage.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Recover;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;

@Service
public class RetryServiceImpl implements RetryService{

    private int count=1;

    @Autowired
    private BookService bookService;

    @Override
    @Retryable(value = Exception.class,maxAttempts = 5,backoff = @Backoff(delay = 3000,multiplier = 1))
    public void retryTest() {
        System.out.println("开始"+count);
        count++;
        bookService.findAllBook();
        System.out.println("结束");
    }

    @Recover
    public void recoverMethod(){
        System.out.println("重试依旧失败");
        count=1;
    }
}
